package com.llp.declaresystem.mapper;

import com.llp.declaresystem.domain.dto.HighQueryProjectDto;
import com.llp.declaresystem.domain.dto.ProjectDto;
import com.llp.declaresystem.domain.entity.Project;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author NASK
* @description 针对表【project(项目信息表)】的数据库操作Mapper
* @createDate 2022-11-23 16:22:33
* @Entity com.llp.declaresystem.entity.Project
*/
@Mapper
public interface ProjectMapper extends BaseMapper<Project> {
    /**
     * 根据project_id查询项目信息
     * @param projectId
     * @return
     */
    @Select("select * from project where project_id=#{projectId};")
    Project selectAllByProjectId(Integer projectId);

    /**
     * 查询所有项目
     * @return
     */
    @Select("select * from project;")
    List<Project> selectAllProjects();

    /**
     * 根据projectId进行查询
     * @param pid
     * @return
     */
    @Select("select * from project where project_id=#{pid};")
    Project selectByPid(Integer pid);

    /**
     * 专家根据categoryid更新项目信息
     * @param project
     * @return
     */
    @Update("update project set expert_opinion=#{expertOpinion},score=#{score},ispass=1 where project_id=#{projectId}")
    int updateProjectByProjectId(Project project);

    /**
     * 单位根据categoryid更新项目信息
     * @param project
     * @return
     */
    @Update("update project set projectname=#{projectname},applicant=#{applicant},grade=#{grade}, " +
            "education=#{education},status=#{status},future=#{future},analysis=#{analysis}, " +
            "way=#{way},result=#{result},capital=#{capital} where project_id=#{projectId}")
    int updateProjectByPid(Project project);

    /**
     * 根据categoryid进行查询
     * @param CategoryId
     * @return
     */
    @Select("select project.* from project join project_category pc on project.categoryid = pc.categoryid where project.categoryid =#{CategoryId} ")
    List<Project> selectProjectByCategoryId(Integer CategoryId);
    /**
     * 通过expertId、categoryid去查找项目信息
     * @param categoryId
     * @return
     */
    @Select("select pc.categoryname,project.* from project left join project_category pc on pc.categoryid=project.categoryid where project.categoryid =#{categoryId} ")
    List<ProjectDto> selectProjectInfoByCategoryId(@Param("categoryId") Integer categoryId);

    /**
     * 根据categoryid进行插入操作
     * 新增时默认ispass是0 未审批
     * @param project
     * @return
     */
    @Insert("insert into project(categoryid, unitid, applicant, grade, education, fill_date, status, future, analysis, way, result, projectname, capital,ispass) " +
            " values(#{categoryid},#{unitid},#{applicant},#{grade},#{education},#{fillDate},#{status},#{future},#{analysis},#{way},#{result},#{projectname},#{capital},0)")
    int insertProjectByCategoryid(Project project);

    /**
     * 根据projectname进行模糊查询
     * @param projectName
     * @return
     */
    @Select("select pc.categoryname,project.* from project left join project_category pc on pc.categoryid = project.categoryid where project.projectname like #{projectName}")
    List<ProjectDto> selectByProjectName(@Param("projectName") String projectName);

    /**
     * 根据Categoryid、Capital进行模糊查询
     * @param categoryid
     * @param capital
     * @return
     */
    @Select("select pc.categoryname,project.* from project left join project_category pc on pc.categoryid = project.categoryid where project.categoryid=#{categoryid} and project.capital like concat('%',#{capital},'%')")
    List<HighQueryProjectDto> selectByCategoryidAndCapital(@Param("categoryid") Integer categoryid,@Param("capital") String capital);

    @Select("select pc.categoryname,project.* from project left join project_category pc on pc.categoryid = project.categoryid where project.capital like concat('%',#{capital},'%')")
    List<HighQueryProjectDto> selectByCapital(@Param("capital") String capital);
  }




